﻿BoxSportSystem.ventasEstadisticas = (function () {
    var viewModel = kendo.observable({
        ventaDataSource: {},
        anio:"",
        createReport: function () {
            onShow();
        }
    });

    function onShow(e) {
        var anio = viewModel.get("anio");
        $.ajax({
            url: BoxSportSystem.config.urlServiceVenta + "?anio=" + anio,
            dataType: "json",
            success: function (data) {
                viewModel.set("ventaDataSource", data);
                console.log(data);
                $('#container').highcharts({
                    chart: {
                        type: 'column'
                    },
                    title: {
                        text: 'Box Sport Corporación'
                    },
                    subtitle: {
                        text: 'Reporte de Ventas del año '+anio
                    },
                    xAxis: {
                        categories: [
                            'Ene',
                            'Feb',
                            'Mar',
                            'Abr',
                            'May',
                            'Jun',
                            'Jul',
                            'Aug',
                            'Sep',
                            'Oct',
                            'Nov',
                            'Dic'
                        ]
                    },
                    yAxis: {
                        min: 0,
                        title: {
                            text: 'Unidad'
                        }
                    },
                    tooltip: {
                        headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
                        pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
                            '<td style="padding:0"><b>{point.y:.1f} S/.</b></td></tr>',
                        footerFormat: '</table>',
                        shared: true,
                        useHTML: true
                    },
                    plotOptions: {
                        column: {
                            pointPadding: 0.1,
                            borderWidth: 0
                        }
                    },
                    series: [{
                        name: 'Ventas',
                        data: data//[49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]

                    }]

                });
            }
        });
    }

    return {
        viewModel: viewModel,
        onShow: onShow
    };
})(window);
